package org.logtime.blog.exception;

/**
 * @version: 1.0
 * @Author: itmins
 * @Email: itmins@gmail.com
 */
@SuppressWarnings("serial")
public class ApiException extends RuntimeException {

	public static final long USER_ACCESS_ERROR_CODE = 10020;

	public static final long ASK_REQUEST_ERROR_CODE = 10010;

	public static final long BLOG_NOT_INIT_ERROR_CODE = 10040;

	public static final long REQUEST_TIMEOUT_ERROR_CODE = 10030;

	public static final long SYSTEM_INTERNAL_ERROR_CODE = 10000;

	public static final long DATA_VALIDATION_ERROR_CODE = 10050;

	public ApiException(Exception e) {
		super(e.getMessage());
		if (e instanceof ApiException) {
			this.errorCode = ((ApiException) e).getErrorCode();
		} else {
			this.errorCode = SYSTEM_INTERNAL_ERROR_CODE;
		}
	}

	public ApiException(long errorCode) {
		this(errorCode, null);
	}

	public ApiException(String errorMessage) {
		this(SYSTEM_INTERNAL_ERROR_CODE, errorMessage);
	}

	public ApiException(long errorCode, String errorMessage) {
		super(errorMessage);
		this.errorCode = errorCode;
	}

	private long errorCode;

	public long getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(long errorCode) {
		this.errorCode = errorCode;
	}
}